<?php
session_start();
include "inc/common.php";
	function checkSession()
	{
		$account = strtolower($_REQUEST['account']);
		if(isset($account))
		{			
			//do nothing 代表第一次進入有取得account資料					
			$accountCriteria = new Criteria();			
			$accountCriteria->add(PermissionListsPeer::ACCOUNT,$account);
			$userAccount = PermissionListsPeer::doSelect($accountCriteria);
			if(!empty($userAccount))
			{
				$_SESSION['account'] = $account;
				/**
				 * 
				 *取得User物件
				 */
				$c = new Criteria();
				$c->add(UserPeer::ACCOUNT,$account);
				$user = UserPeer::doSelect($c);
				
				$per = $userAccount[0]->getPermission();				
				if($per == 'admin')
				{
					$_SESSION['controlTab'] = "inc/adminTabInc.php";
					$_SESSION['permission'] = "admin";
					$_SESSION['name'] = $user[0]->getName();
				}	
				else
				{
					$_SESSION['controlTab'] = "inc/deptTabInc.php"; 
					$_SESSION['permission'] = "dept";
					$_SESSION['name'] = $user[0]->getName();
				}			
			} 
			else
			{
				//針對學生處理
				$c = new Criteria();
				$c->add(UserPeer::ACCOUNT,$account);
				$result = UserPeer::doSelect($c);
				if(!empty($result))
				{
					$_SESSION['controlTab'] ="inc/studentTabInc.php";
					$_SESSION['permission'] ="student";					
					$_SESSION['name'] = $result[0]->getName();
					$_SESSION['account'] = $account;
				}
				else
				{
					echo "<script language='javascript'>";
					echo "window.location='http://www.hit.edu.tw/teacher.jsp'";
					echo "</script>";
				}
			}
		}
		else
		{
			if(!empty($_SESSION['name']))
			{
				
			}
			else
			{
				header("location:http://www.hit.edu.tw/teacher.jsp");
			}
		}
	}
?>